﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace peonwar
{
    [Serializable]
    public struct Map
    {
        public string Name;
        public int Length;
        public int Background;
        public Vector2 BackgroundPos;
        public int Music;
        public bool Looped;
        public Color Chatcolor;

        public Map(string name, int length, int background, int x, int y, int music, bool loop, Color chatcolor)
        {
            this.Name = name;
            this.Length = length;
            this.Background = background;
            this.BackgroundPos = new Vector2(x, y);
            this.Music = music;
            this.Looped = loop;
            this.Chatcolor = chatcolor;
        }

        public override string ToString()
        {
            switch (this.Name)
            {
                case "Forest":
                    return GameData.GameString[33];
                case "Desert":
                    return GameData.GameString[34];
                case "Winter":
                    return GameData.GameString[104];
                case "Temple":
                    return GameData.GameString[105];
                case "Frontier":
                    return GameData.GameString[106];
                case "Grass":
                    return GameData.GameString[107];
                case "City":
                    return GameData.GameString[108];
            }
            return "";
        }

        public bool IsEqual(Map map)
        {
            return this.Name == map.Name;
        }
    }

    static class MapManager
    {
        // Liste des maps
        public static Map[] MapList;
        public static int MapIndex = 0;


        public static Map Grass =    new Map("Grass",  1360, 1, 680, 202, 0, false, Color.Black);
        public static Map Winter =   new Map("Winter", 1280, 3, 640, 120, 1, false, Color.Black);
        public static Map Forest =   new Map("Forest", 1665, 0, 640, 125, 2, false, Color.Yellow);
        public static Map Desert =   new Map("Desert", 2300, 2, 1020, 160, 3, true, Color.Black);
        public static Map Temple =   new Map("Temple", 1600, 4, 640, 165, 4, true, Color.White);
        public static Map City = new Map("City", 1800, 6, 898, 183, 6, false, Color.Black);
        public static Map Frontier = new Map("Frontier", 1600, 5, 640, -30, 5, false, Color.Black);

        public static void UpdateMapList()
        {
            int progress = SettingManager.CurrentProfil.Progress;
            List<Map> maplist = new List<Map>();

            maplist.Add(Grass);
            if (progress > 3)
                maplist.Add(Winter);
            if (progress > 5)
                maplist.Add(Forest);
            if (progress > 7)
                maplist.Add(Desert);
            if (progress > 9)
                maplist.Add(Temple);
            if (progress > 10)
                maplist.Add(City);
            if (progress > 12)
                maplist.Add(Frontier);

            MapManager.MapList = maplist.ToArray();
            MapIndex = 0;
        }
    }
}
